package com.headwind.logistics.logistics.controller;

import com.headwind.logistics.common.constant.UserSessionKey;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.common.pojo.Customer;
import com.headwind.logistics.logistics.service.intl.LogisticsCustomerServiceIntl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @Author 小恶魔
 * @Date 2020-07-20 10:45
 * @Version 1.0
 * @DESCRIPTION 客户控制器层
 */
@Controller
public class CustomerController {
    @Resource
    private LogisticsCustomerServiceIntl customerServiceIntl;

    //api统一响应接口
    @Resource
    private ResultGenerator resultGenerator;

    /**
     * 前台客户登录
     * @param customer
     * @param session
     * @return
     */
    @PostMapping("/logistics/customerLogin")
    @ResponseBody
    public RestResult customerLogin(@RequestBody Customer customer, HttpSession session){

        Customer cus = customerServiceIntl.customerLogin(customer);

        if (cus != null){

            //把顾客对象存入session
            session.setAttribute(String.valueOf(UserSessionKey.CUSTOMER),cus);

            return resultGenerator.getSuccessResult();

        }

        return resultGenerator.getFailResult("失败了哦");
    }


}
